package com.niit.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.Note;
import com.niit.bean.NoteRepo;
import com.niit.bean.User;
import com.niit.service.NoteRepoService;
import com.niit.service.NoteService;
import com.niit.service.impl.NoteRepoServiceImpl;
import com.niit.service.impl.NoteServiceImpl;
import com.niit.utils.Page;
import com.niit.utils.WebKit;

@WebServlet("/ShowBriefNoteController")
public class ShowBriefNoteController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String pagenum = request.getParameter("curPage");
		String repoId = request.getParameter("repoId");// 获取仓库id

		User user = (User) request.getSession().getAttribute("user");//获取已登录的user

		// 获取笔记本仓库
		NoteRepoService nrs = new NoteRepoServiceImpl();
		List<NoteRepo> list = nrs.findReposByUser(user);
		
		NoteService ns = new NoteServiceImpl();
		
		Page<Note> notes = ns.findNotes(user, repoId, pagenum, WebKit.getServletURI(request));

		request.setAttribute("repoid", repoId);
		request.setAttribute("page", notes);
		request.setAttribute("list", list);
		request.getRequestDispatcher("/jsp/user/notebook.jsp").forward(request,	response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
